<template>
  <div class="app-container">
    <!-- *************************************搜索区************************************* -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="90px"
    >
      <!--  <el-form-item :label="$t('时间选择')">
        <!~~ 时间选择 ~~>
        <el-date-picker
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          v-model="queryParams.createTime"
          type="date"
          clearable
        />
      </el-form-item>

      <el-form-item :label="$t('审核状态')">
        <el-select clearable v-model="queryParams.status">
          <!~~ 1.未审核
            2.已审核
            3.取消盘点 ~~>
          <el-option :label="$t('未审核')" :value="1" />
          <el-option :label="$t('已审核')" :value="2" />
          <el-option :label="$t('取消盘点')" :value="3" />
        </el-select>
      </el-form-item>-->

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >
          {{ $t("搜索") }}
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
          {{ $t("重置") }}
        </el-button>
      </el-form-item>
    </el-form>
    <!-- 增删改查 -->
    <el-row style="margin: 15px 0" :gutter="10">
      <!-- v-hasPermi="['distribution:purchase:createPurchaseOrder']" -->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          v-hasPermi="[
            'istribution:distributorApply:insertDistributorProportion',
          ]"
          size="mini"
          @click="handleAdd"
        >
          <!-- 新增 -->
          {{ $t("添加") }}
        </el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading"   ref="TableRef"  :data="tableData" row-key="menuId">
      <!-- 租户 推荐人/分成 推荐人上级/分成 总公司/分成 操作 -->
      <!-- 租户 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="referrerRegisterName"
        label="租户"
      />
      <!-- 推荐人/分成 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="type"
        label="推荐人/分成"
      >
        <template slot-scope="{ row }">
          <div>{{ row.referrerName || "-" }}</div>
          <div style="color: green">{{ row.referrerProportion }}</div>
        </template>
      </el-table-column>
      <!-- 推荐人上级/分成 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="type"
        label="推荐人上级/分成"
      >
        <template slot-scope="{ row }">
          <div>{{ row.referrerSuperName || "-" }}</div>
          <div style="color: green">{{ row.referrerSuperProportion }}</div>
        </template>
      </el-table-column>
      <!-- 总公司/分成 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="type"
        label="总公司/分成"
      >
        <template slot-scope="{ row }">
          <div>{{ row.headOfficeName || "-" }}</div>
          <div style="color: green">{{ row.headOfficeProportion }}</div>
        </template>
      </el-table-column>

      <!-- 操作 -->
      <el-table-column
        align="center"
        fixed="right"
        :label="$t('操作')"
        :width="calWidth(200, 250, 200)"
      >
        <template slot-scope="{ row }">
          <el-button
            v-hasPermi="['distribution:distributorProportion:edit']"
            type="text"
            size="small"
            @click="handleEdit(row)"
          >
            <!-- 修改 -->
            {{ $t("编辑") }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="pageTotal > 0"
      :total="pageTotal"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <AddAndEdit
      :show.sync="addAndEdit.show"
      @getList="getList"
      :formData="addAndEdit.formData"
      :type="addAndEdit.type"
    />
  </div>
</template>

<script>
import AddAndEdit from "./addAndEdit.vue";
import { list } from "@/api/platform/divisionRelation";
export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  name: "divisionRelation",
  components: { AddAndEdit },
  data() {
    return {
      /**审核 */
      addAndEdit: {
        show: false,
        type: "",
        formData: {},
      },
      form: {},
      tableCheck: [],
      tableData: [],
      /**数据总条数 */
      pageTotal: 0,
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  async created() {
    this.getList();
  },

  methods: {
    handleAdd() {
      this.addAndEdit.show = true;
      this.addAndEdit.type = "add";
    },
    handleEdit(row) {
      this.addAndEdit.show = true;
      this.addAndEdit.type = "edit";
      this.addAndEdit.formData = JSON.parse(JSON.stringify(row));
    },
    // 取消申请
    cancel() {},
    /** 查询菜单列表 */
    getList() {
      this.loading = true;
      console.log(` ==>`, JSON.parse(JSON.stringify(this.queryParams)));
      list(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.pageTotal = res.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.value1 = null;
      Object.keys(this.queryParams).forEach((key) => {
        this.queryParams[key] = null;
      });
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;

      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped></style>
